<template>
    <div>
<el-dialog title="修改密码" :visible.sync="dialogFormVisible" @close="cleartext">
<el-form ref="form" :model="pass" label-width="80px">
  <el-form-item label="旧密码">
    <el-input v-model="pass.oldPassword"></el-input>
  </el-form-item>
  <el-form-item label="新密码">
    <el-input v-model="pass.password"></el-input>
  </el-form-item>
  <el-form-item label="重复新密码">
    <el-input v-model="pass.rePassword"></el-input>
  </el-form-item>
</el-form>
  <div slot="footer" class="dialog-footer">
    <el-button type="primary" @click="setpass">确 定</el-button>
  </div>
</el-dialog>
 </div>
</template>
<script>
import {http,updatePwd} from '../../api/api.js'
export default {
    props:['type',"btn"],
    data() {
        return {
          dialogFormVisible:this.type ,//对话框状态
          pass:{
              oldPassword:'',
              password:'',
              rePassword:''
          } 
        }
    },
     watch:{
        type(a,b){
            //当父级传入的值发生改变，修改对话框的状态
         this.dialogFormVisible = this.type
      }
    },
    methods: {
        //清空数据
        cleartext(){
     for( var i in this.pass){
       this.pass[i] =''
}
    //调去的父级函数
      this.btn()
        },
        setpass(){
        if(this.pass.oldPassword ==''){
this.$message.error('请输入旧密码')
        }else if(this.pass.password == ''){
this.$message.error('请输入新密码')
        }else if(this.pass.rePassword == ''){
this.$massage.error('请再次输入新密码')
        }else if(this.pass.password !=this.pass.rePassword){
this.$message.error('两次密码不一致')
        }else{
            this.$http.post(http + updatePwd,this.pass,{emulateJSON:true}).then((data)=>{
            // console.log(data)
        if(data.data.msg =='成功'){
        this.$message.error('修改成功')
        }else{

        }
            },(err)=>{
      this.$message.error(err.data.message)
            })
           }
         }
    },

}
</script>